﻿using ConfExpert.Forms.Base;
using DevExpress.XtraGrid.Views.Grid;
using DevTeam;

using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;

namespace ConfExpert.Forms.Depo._7C
{
    public partial class DosyaKaydir : XForm
    {
        int CikisPartisiId;
        public DosyaKaydir(int CikisPartisiId)
        {
            InitializeComponent();
            this.CikisPartisiId = CikisPartisiId;
        }

        private void DosyaKaydir_Load(object sender, EventArgs e)
        {
            
            gleAtelye.Edit.Assign(RI(Rp.Atelye));

            gridView1.Init("GetPartiDosya", CikisPartisiId);
            gridView1.MakeReadOnly("Sec");
            gridView1.AddColumn("Secilen", typeof(int), "Iif(Sec=1,GomlekAdedi,0)");
            gridView1.FormatAsNumber(0, "ExecutionAdedi", "GomlekAdedi", "Secilen");
            gridView1.AddSummary("ExecutionAdedi", "GomlekAdedi", "Secilen");
            gridView1.YanYanaGetir("Sec:DosyaNo");
            gridView1.BestFitColumns();

            gridView1.OptionsBehavior.EditorShowMode = DevExpress.Utils.EditorShowMode.MouseDown;
            gridView1.OptionsView.EnableAppearanceOddRow = gridView1.OptionsView.EnableAppearanceEvenRow = false;
            gridView1.RowStyle += gridView1_RowStyle;
            gleAtelye.EditValueChanged += gleAtelye_EditValueChanged;
            btn.Enabled = false;
            btn.ItemClick += btn_ItemClick;


        }

        void gleAtelye_EditValueChanged(object sender, EventArgs e)
        {
            btn.Enabled = intParse(gleAtelye.EditValue)>0;
        }

        void btn_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView1.EndEditing();
            List<string> dosyalar = new List<string>();
            foreach (DataRow dr in gridView1.DataTable().Select("Sec=1"))
                dosyalar.Add(dr["DosyaNo"].ToString());

            ExecuteNonQuery("UpdPartiDosya", CikisPartisiId, string.Join(",", dosyalar.ToArray()), intParse(gleAtelye.EditValue));
            
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        void gridView1_RowStyle(object sender, RowStyleEventArgs e)
        {
            GridView view = sender as GridView;
            if (e.RowHandle > -1)
            {
                if ((bool)gridView1.GetRowCellValue(e.RowHandle, "Sec") == true)
                    e.Appearance.BackColor = e.Appearance.BackColor2 = Color.YellowGreen;   // Color.FromArgb(255, 192, 0);
                else
                    e.Appearance.Combine((e.RowHandle & 1) != 0 ? view.Appearance.EvenRow : view.Appearance.OddRow);
            }
        }


    }
}
